home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-24 | 7.9 KB | 303 lines | [TEXT/PJMM] |
- {Some selected dialog utilities from my private library}
- {Note: These are considerably safer than most similar dialog units I have seen, since they check}
- {the item kind rather than just blindly assuming that the programmer know what he/she is doing.}
-
- unit DialogUtils;
-
- interface
-
- {$IFC UNDEFINED THINK_PASCAL}
- uses
- Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf;
- {$ENDC}
-
- procedure HighlightDItem (theDialog: DialogPtr; itemNo: integer);
- procedure HiliteDItem (theDialog: DialogPtr; itemNo: integer);
- procedure EnableDItem (theDialog: DialogPtr; itemNo: integer);
- procedure DisableDItem (theDialog: DialogPtr; itemNo: integer);
- function TestDItemEnable (theDialog: DialogPtr; itemNo: integer): boolean;
- procedure HideDItem (theDialog: DialogPtr; itemNo: integer);
- procedure ShowDItem (theDialog: DialogPtr; itemNo: integer);
- procedure UpdDialogRect (theDialog: DialogPtr; theRect: Rect);
- procedure SetTextDItem (theDialog: DialogPtr; itemNo: integer; theString: Str255);
- function GetTextDItem (theDialog: DialogPtr; itemNo: integer): Str255;
- procedure SetBooleanDItem (theDialog: DialogPtr; itemNo: integer; theBoolean: Boolean);
- function GetBooleanDItem (theDialog: DialogPtr; itemNo: integer): Boolean;
- procedure ToggleBooleanDItem (theDialog: DialogPtr; itemNo: integer);
- function GetDItemBox (theDialog: DialogPtr; itemNo: integer): Rect;
- function StdFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
- function MyFindControl (plats: Point; theDialog: DialogPtr; var theItem: ControlHandle): integer;
-
- implementation
-
-
- procedure HighlightDItem (theDialog: DialogPtr; itemNo: integer);
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- HiliteControl(ControlHandle(item), 1); {10 för button, 11 för radio?}
- end;
-
- procedure HiliteDItem (theDialog: DialogPtr; itemNo: integer);
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- HiliteControl(ControlHandle(item), 1); {10 för button, 11 för radio?}
- end;
-
- procedure EnableDItem (theDialog: DialogPtr; itemNo: integer);
- var
- kind, realkind: integer;
- item: Handle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, item, box);
- if item = nil then
- SysBeep(1)
- else
- begin
- realkind := BitAnd(kind, 127);
- case realkind of
- 8, 16: {statText, editText}
- SetDItem(theDialog, itemNo, realkind, item, box); {meningslöst?}
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio - men vad är 4?}
- HiliteControl(ControlHandle(item), 0);
- otherwise
- SysBeep(1);
- end; {case}
- end;
- end;
-
- procedure DisableDItem (theDialog: DialogPtr; itemNo: integer);
- var
- kind, realkind: integer;
- item: Handle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, item, box);
- if item = nil then
- SysBeep(1)
- else
- begin
- realkind := BitAnd(kind, 127);
- case realkind of
- 8, 16: {statText, editText}
- SetDItem(theDialog, itemNo, kind + itemDisable, item, box); {meningslöst?}
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio - men vad är 4?}
- HiliteControl(ControlHandle(item), 255);
- otherwise
- SysBeep(1);
- end; {case}
- end;
- end;
-
- function TestDItemEnable (theDialog: DialogPtr; itemNo: integer): boolean;
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- TestDItemEnable := ControlHandle(item)^^.contrlHilite <> 255;
- end;
-
- procedure HideDItem (theDialog: DialogPtr; itemNo: integer);
- var
- kind, realkind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- begin
- realkind := BitAnd(kind, 127);
- case realkind of
- 8, 16: {statText, editText}
- SetIText(handle(item), ''); {Nån bättre metod finns väl}
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio - men vad är 4?}
- HideControl(ControlHandle(item));
- otherwise
- SysBeep(1);
- end; {case}
- end;
- end;
-
- procedure ShowDItem (theDialog: DialogPtr; itemNo: integer);
- var
- kind, realkind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- begin
- realkind := BitAnd(kind, 127);
- case realkind of
- 8, 16:
- ; {statText, editText}
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio - men vad är 4?}
- ShowControl(ControlHandle(item));
- otherwise
- SysBeep(1);
- end; {case}
- end;
- end;
-
- {UpdDialog med rektangel i stället för region}
- procedure UpdDialogRect (theDialog: DialogPtr; theRect: Rect);
- var
- rgn: RgnHandle;
- begin
- rgn := NewRgn;
- RectRgn(rgn, theRect);
- UpdtDialog(theDialog, rgn);
- DisposeRgn(rgn);
- end;
-
- {Ett par triviala tvåradare - plus säkerhetskoll!}
- {Text till StatText/EditText}
- procedure SetTextDItem (theDialog: DialogPtr; itemNo: integer; theString: Str255);
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- begin
- {Kolla kind}
- kind := BitAnd(kind, 127);
-
- case kind of
- 8, 16: {statText, editText}
- SetIText(handle(item), theString);
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio - men vad är 4?}
- SetCTitle(item, theString);
- otherwise {Övriga har ingen text man kan sätta}
- SysBeep(1);
- end;{case}
- end;
- end;
-
- {Texten från StatText/EditText}
- function GetTextDItem (theDialog: DialogPtr; itemNo: integer): Str255;
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- tmpStr: Str255;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- begin
- {Kolla kind}
- kind := BitAnd(kind, 127);
-
- tmpStr := '';
- case kind of
- 8, 16: {statText, editText}
- GetIText(handle(item), tmpStr);
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio…?}
- GetCTitle(item, tmpStr);
- otherwise {Övriga har ingen text man kan sätta}
- SysBeep(1);
- end;{case}
- GetTextDItem := tmpStr;
- end;
- end;
-
-
- {Ett par triviala tvåradare - plus säkerhetskoll!}
- {Boolean till checkbox/radio}
- procedure SetBooleanDItem (theDialog: DialogPtr; itemNo: integer; theBoolean: Boolean);
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- begin
- {Kolla kind}
- kind := BitAnd(kind, 127);
- case kind of
- 8, 16: {statText, editText}
- if theBoolean then
- SetIText(handle(item), 'true')
- else
- SetIText(handle(item), 'false');
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio - men vad är 4?}
- SetCtlValue(item, integer(theBoolean));
- otherwise {Övriga har ingen text man kan sätta}
- SysBeep(1);
- end;{case}
- end;
- end;
-
- {Boolean från checkbox/radio}
- function GetBooleanDItem (theDialog: DialogPtr; itemNo: integer): Boolean;
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- if item = nil then
- SysBeep(1)
- else
- begin
- {Kolla kind}
- kind := BitAnd(kind, 127);
-
- GetBooleanDItem := false;
- case kind of
- 0, 1, 2, 4, 5, 6: {button, checkbox, radio…?}
- GetBooleanDItem := boolean(GetCtlValue(item));
- otherwise {Övriga har inget värde}
- SysBeep(1);
- end;{case}
- end;
- end;
-
- procedure ToggleBooleanDItem (theDialog: DialogPtr; itemNo: integer);
- begin
- SetBooleanDItem(theDialog, itemNo, not GetBooleanDItem(theDialog, itemNo));
- end;
-
- function GetDItemBox (theDialog: DialogPtr; itemNo: integer): Rect;
- var
- kind: integer;
- item: ControlHandle;
- box: Rect;
- tmpStr: Str255;
- begin
- GetDItem(theDialog, itemNo, kind, Handle(item), box);
- GetDItemBox := box;
- end;
-
- end.